/**
 *    Copyright 2009-2015 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**jdbc类型与java类型之间的转换：
 * <br/>1、PreparedStatement对象为参数占位符设置值时，需要调用PreparedStatement接口中提供的一系列setXXX方法，将java类型转换为对应的jdbc类型并为参数占位符赋值
 * <br/>2、执行sql语句获取ResultSet对象后，需要调用ResultSet对象的getXXX方法获取字段值，此时会将jdbc类型转换为java类型
 * @author Clinton Begin
 */
public interface TypeHandler<T> {

	/**为PreparedStatement对象设置参数
	 * @param ps
	 * @param i
	 * @param parameter
	 * @param jdbcType
	 * @throws SQLException
	 */
	void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;

	/**根据列名称获取该列的值
	 * @param rs
	 * @param columnName
	 * @return
	 * @throws SQLException
	 */
	T getResult(ResultSet rs, String columnName) throws SQLException;

	/**根据列索引获取该列的值
	 * @param rs
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 */
	T getResult(ResultSet rs, int columnIndex) throws SQLException;

	/**根据存储过程调用结果
	 * @param cs
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 */
	T getResult(CallableStatement cs, int columnIndex) throws SQLException;

}
